var mainApp = angular.module("mainApp");

mainApp.controller("configController", function($scope, $http, $timeout) {
	var cm = $scope.cm = {
		showMessage : false
	};

	cm.query = function() {
		$http.post("system/config/list.do").success(function(data) {
			cm.configlist = data.configlist;
		})
	}

	cm.query();

	cm.edit = function() {
		var confs = cm.getconfig();
		$http.post("system/config/edit.do", JSON.stringify(confs), {
			headers : {
				'Content-Type' : 'application/json;charset=utf-8'
			}
		}).success(function(data) {
			cm.result = data.result;
			if (cm.result == 1) {
				cm.message = '操作成功！';
			} else {
				cm.message = "操作失败！"
			}
			cm.isShowMsg = true;
			cm.showMsg();
		})
	}

	cm.showMsg = function() {
		$timeout(function() {
			cm.isShowMsg = false;
		}, 3000);
	}

	cm.getconfig = function() {
		var configs = [];
		angular.forEach(cm.configlist, function(conf) {
			configs.push({
				id : conf.id,
				key : conf.key,
				value : conf.value,
				description : conf.description
			});
		})
		return configs;
	}
})

